﻿using Core;
using Core.Battle;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class TerminalController : IEntityController
{
    private IEntity entity;

    private AbilitySummoner summoner;

    public TerminalController(IEntity entity)
    {
        this.entity = entity;
        summoner = new AbilitySummoner(entity);
    }

    public Ability GetAbility(List<IEntity> opponents)
    {
        
        var cmd = Console.ReadLine();

        switch (cmd)
        {
            case "W":
                summoner.PushElement(Element.Kind.Water);
                return null;

            case "G":
                summoner.PushElement(Element.Kind.Grass);
                return null;

            case "A":
                summoner.PushElement(Element.Kind.Air);
                return null;

            case "S":
                Console.WriteLine($"正在释放: {summoner.Elements[0]} {summoner.Elements[1]} {summoner.Elements[2]}");
                if (summoner.TrySummon() is AbilityDef def)
                {
                    Console.WriteLine($"释放了: {def.name}");
                    Console.WriteLine("选择目标:\n-1:自己");
                    for (int i = 0; i < opponents.Count; i++)
                    {
                        Console.WriteLine($"{i}:{opponents[i].Name}");
                    }

                    int target = int.Parse(Console.ReadLine());

                    IEntity targetEntitiy = null;
                    if (target == -1) targetEntitiy = entity;
                    else targetEntitiy = opponents[target];

                    return new Ability(entity, new IEntity[] { targetEntitiy }, def);
                }
                return null;

            default:
                Console.WriteLine("Error element input.");
                break;
        }
        return null;
    }
}
